#include "MyString.h"
#include <string.h>
#include <stdio.h>


void InitMyString(Mystr *s)
{
    s->len = 0;
    memset(s->str,0,Size);
}

//替换原来的字符串
void InsertStr(Mystr *s,char *newStr)
{
    strncpy(s->str,newStr,Size - 1);
    s->len = strlen(s->str);
}

void AppendStr(Mystr *s, char *newStr)
{
    strncat(s->str,newStr,Size - 1 - s->len);
    s->len = strlen(s->str);
} 

void PrintStr(Mystr *s,bool HaveEnter)
{
    if(HaveEnter)
        printf("姓名：%s  ",s->str);
    else
        printf("号码：%s\n",s->str);
}

void RmString(Mystr *s,  char *str)
{
    char *dest = strstr(s->str,str); 
    while(dest !=NULL)
    {
        char *back = dest + strlen(str);
        while(*back != '\0')
        {
            *dest++ = *back++;
        }
        *dest = '\0';
        dest = strstr(s->str,str);
    }
    s->len = strlen(s->str);
}

bool IsStrEqual(Mystr *s, Mystr *str)
{
    return strcmp(s->str,str->str) == 0;
}

char *GetSPtr(Mystr *s)
{
    return s->str;
}

void GetStr(Mystr *s)
{
    InitMyString(s);
    char c = 0;
    while((c = getchar()) != '\n' && s->len < Size - 1)
    {
        s->str[s->len++] = c;
    }
}
